//
//  HomeStyleThirdCell.m
//  Shengzhuli
//
//  Created by FXGuo on 2017/5/12.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "HomeStyleThirdCell.h"
#import "HomeThirdCollectionViewCell.h"

@interface HomeStyleThirdCell()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *nameLab;
@property (weak, nonatomic) IBOutlet UIButton *subTitleBtn;


@property (weak, nonatomic) IBOutlet UICollectionView *collection;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionHeightCons;
@property (nonatomic,strong) NSArray *types;

@end

@implementation HomeStyleThirdCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.collection.dataSource = self;
    self.collection.delegate = self;
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
    flow.itemSize = CGSizeMake((ScreenW-2)/3.0, 40);
    flow.minimumInteritemSpacing = 1;
    flow.minimumLineSpacing = 1;
    flow.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.collection.collectionViewLayout = flow;
    [self.collection registerNib:[UINib nibWithNibName:NSStringFromClass([HomeThirdCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([HomeThirdCollectionViewCell class])];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.types.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HomeThirdCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([HomeThirdCollectionViewCell class]) forIndexPath:indexPath];
    cell.model = self.types[indexPath.row];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.typeClickBlock) {
        self.typeClickBlock(self.model.typeList[indexPath.item]);
    }
}

- (void)setModel:(HomeGoodsModel *)model
{
    _model = model;
    self.nameLab.text = model.recommendName;
    [self.subTitleBtn setTitle:[NSString stringWithFormat:@"%@ ＞",model.subtitle] forState:UIControlStateNormal];
    self.types = model.typeList;
    [self.collection reloadData];
}
- (IBAction)typeClick:(UIButton *)btn
{
    HomeGoodsTypeModel *typeModel = [[HomeGoodsTypeModel alloc]init];
    typeModel.ID = self.model.productTypeParentId;
    typeModel.productTypeName = self.model.productTypeName;
    if (self.typeClickBlock) {
        self.typeClickBlock(typeModel);
    }
}

@end
